import 'package:XinXiZiXun/common/apis/apis.dart';
import 'package:XinXiZiXun/common/entitys/entitys.dart';
import 'package:XinXiZiXun/common/utils/screen.dart';
import 'package:XinXiZiXun/common/utils/utils.dart';
import 'package:XinXiZiXun/common/values/colors.dart';
import 'package:XinXiZiXun/common/values/constants.dart';
import 'package:XinXiZiXun/pages/homepage/components/components.dart';
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List<BannerEntity> _bannerArry;

  ///加载轮播图
  _handleLoadBannerData() async {
    Map<String, dynamic> params = {};

    HomePageBannerEntity responseEntity =
        await HomePageBannerApi.homePageBanner(
      params: params,
    );

    if (responseEntity.tag == 1) {
      _bannerArry = responseEntity.resultEntity.dataList;

      setState(() {});
    } else {
      AlertUtil.fromBottom(responseEntity.message, context);
    }
  }

  @override
  void initState() {
    _handleLoadBannerData();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          '首页',
          style: TextStyle(
            color: AppColors.primaryBlackColor,
            fontFamily: 'Montserrat',
            fontSize: duSetScaleFontSize(36),
            fontWeight: FontWeight.w600,
          ),
        ),
        leading: null,
        backgroundColor: AppColors.primaryWhiteColor,
        elevation: 0,
      ),
      body: Padding(
        padding: const EdgeInsets.all(kDefaultPadding),
        child: Column(
          children: [
            handleBanner(context, _bannerArry),
          ],
        ),
      ),
    );
  }
}
